<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box01{
            position:fixed;bottom:10px;right:10px;width: 100px;height: 100px;background-color:red;
        }
        .redbox {
            width: 200px;
            height: 200px;
            border-radius: 10px;
            background-color: red;
        }
        #app{
            position: relative;
            border: 1px solid black;
            width: 500px;
            height: 400px;
        }
    </style>
</head>

<body style="height: 2000px;">
    <div id="app">
        <div class="redbox" v-drag >我可以被拖拽</div>
        <div class="box01" v-pagetop >
            回到顶部
        </div>
    </div>
</body>

</html>
<script src="./js/vue2.js"></script>
<script src="./js/myDirective.js"></script>
<script>

    Vue.directive('pagetop', {
        inserted: function (el) {
            el.onclick = function () {
                document.body.scrollTop = 0;
                document.documentElement.scrollTop = 0;
            }
        }
    })

    let vm = new Vue({
        el: "#app",
    });


</script>